<template>
  <div class="login-form">
    <div class="g-form">
      <div class="g-form-line">
        <div class="form-group">
          <label>用户名:</label>
          <input type="text" class="form-control" placeholder="请输入用户名" v-model="usernameModel">
        </div>
        <span class="g-form-error">{{ userErrors.errorText }}</span>
      </div>
      <div class="g-form-line">
        <div class="form-group">
          <label>密码:</label>
          <input type="password" class="form-control" placeholder="请输入密码" v-model="passwordModel">
        </div>
        <span class="g-form-error">{{ passwordErrors.errorText }}</span>
      </div>
      <div class="g-form-line">
        <div class="form-group">
          <label>确认密码:</label>
          <input type="password" class="form-control" placeholder="请再次输入密码" v-model="checkPasswordModel">
        </div>
        <span class="g-form-error">{{ checkPassword.errorText }}</span>
      </div>
      <div class="g-form-line">
        <div class="form-group">
          <button type="button" class="btn btn-primary" v-on:click="onLogin">登录</button>
          <button type="reset" class="btn btn-danger">重置</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      'isShow': 'boolean'
    },
    data () {
      return {

      }
    },
    computed: {
      userErrors () {
        let status, errorText
        if (!/@/g.test(this.usernameModel)) {
          status = false
          errorText = '必须包含@'
        }
        else {
          status = true
          errorText = ''
        }
        return {
          status,
          errorText
        }
      },
      passwordErrors () {
        let errorText, status
        if (!/^\w{1,6}$/g.test(this.passwordModel)) {
          status = false
          errorText = '密码不是1-6位'
        }
        else {
          status = true
          errorText = ''
        }
        if (!this.passwordFlag) {
          errorText = ''
          this.passwordFlag = true
        }
        return {
          status,
          errorText
        }
      },
      checkPassword(){
        let status,errorText
        if(this.passwordModel === this.checkPasswordModel){
              status=true
              errorText=''
        }else{
              status=false
              errorText='两次密码不一致，请重新输入！'
        }
        return {
          status,
          errorText
        }
      }
    },
    methods: {
      closeMyself () {
        this.$emit('on-close')
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .dialog-wrap {
    position: fixed;
    width: 100%;
    height: 100%;
  }
  .dialog-cover {
    background: #000;
    opacity: .3;
    position: fixed;
    z-index: 5;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
  .dialog-content {
    width: 50%;
    position: fixed;
    max-height: 50%;
    overflow: auto;
    background: #fff;
    top: 20%;
    left: 50%;
    margin-left: -25%;
    z-index: 10;
    border: 2px solid #464068;
    padding: 2%;
    line-height: 1.6;
  }
  .dialog-close {
    position: absolute;
    right: 5px;
    top: 5px;
    width: 20px;
    height: 20px;
    text-align: center;
    cursor: pointer;
  }
  .dialog-close:hover {
    color: #4fc08d;
  }
</style>
